package cn.sdhuijin.vms.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(name = "t_car")
public class Car extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Column(updatable = false, unique = true)
	private String license;
	@NotBlank(message = "负责人姓名不能为空。")
	private String masterName;
	@NotBlank(message = "负责人手机不能为空。")
	@Length(max = 11, min = 11, message = "手机号码必须为11位")
	private String masterPhone;

	@OneToOne(cascade = CascadeType.ALL)
	private Card card;
	@ManyToOne
	@JoinColumn(name = "org_id")
	private Organization organization;
	@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "car")
	private List<CarRecord> records = new ArrayList<CarRecord>();

	public List<CarRecord> getRecords() {
		return records;
	}

	public void setRecords(List<CarRecord> records) {
		this.records = records;
	}

	public String getLicense() {
		return license;
	}

	public void setLicense(String license) {
		this.license = license;
	}

	public String getMasterName() {
		return masterName;
	}

	public void setMasterName(String masterName) {
		this.masterName = masterName;
	}

	public String getMasterPhone() {
		return masterPhone;
	}

	public void setMasterPhone(String masterPhone) {
		this.masterPhone = masterPhone;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public Card getCard() {
		return card;
	}

	public void setCard(Card card) {
		this.card = card;
	}

	@Override
	public String toString() {
		return "Car [license=" + license + ", masterName=" + masterName
				+ ", masterPhone=" + masterPhone + ", card=" + card
				+ ", organization=" + organization + "]";
	}

}
